package middlewares

import (
	"gin-study/app/http/responses"
	"gin-study/app/services"
	"gin-study/pkg/helper"
	"github.com/gin-gonic/gin"
)

func Auth() gin.HandlerFunc {
	return helper.WarpHandle(func(c *gin.Context) interface{} {
		c.Next()

		return nil

		token := c.GetHeader("Authorization")
		if len(token) == 0 {
			return responses.Unauthorized("请传token", nil)
		}

		user, err := services.User.GetUserByToken(token)

		if err != nil {
			return responses.BadRequest(err.Error(), nil)
		}
		if user == nil {
			return responses.Unauthorized("token无效", gin.H{
				"token": token,
			})
		}

		services.Ctx.SetUser(c, user)

		c.Next()

		return nil
	})

}
